class UserException extends Exception {//自定义一个用户名异常继承于Exception

    public UserException(String message) {//构造方法
        super(message);
    }
}

class PasswordException extends Exception {//自定义一个密码异常继承于Exception

    public PasswordException(String message) {//构造方法
        super(message);
    }
}

class Text {

    static String userName = "lee";
    static String password = "123456";

}

public class TestDemo3 {


    public static void main(String[] args) {
        try {
            login("lee", "123456");
        } catch (UserException e) {
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }

    public static void login(String userName, String password) throws UserException, PasswordException {//自定义login方法并声明用户名异常和密码异常
        if (!Text.userName.equals(userName)) {
            throw new UserException("用户名异常");
        }
        if (!Text.password.equals(password)) {
            throw new PasswordException("密码异常");
        }
        System.out.println("登陆成功！");
    }
}
